﻿using java.time;
using Microsoft.AspNetCore.Mvc;

// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

namespace Learn.API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class TestController : ControllerBase
    {
        // GET api/<TestController>/5
        [HttpGet("{id}")]
        public string Get(int id)
        {
            IEnumerable<int> ints = GenerateFibonacci(id);

            return $"value:{string.Join(',',ints)}";
        }

        IEnumerable<int> GenerateFibonacci(int n)
        {
            if (n >= 1) yield return 1;

            int a = 1, b = 0;
            for (int i = 2; i <= n; ++i)
            {
                int t = b;
                b = a;
                a += t;

                yield return a;
            }
        }

    }
}
